<%
   containerId = 'bubble-chart-widget' + widget.id.to_s
   chartTitle = widget_properties["chartTitle"]
   chartHeight = widget_properties["chartHeight"]
   filterId = widget_properties["filter"].to_i
   xMetric = widget_properties["xMetric"]
   yMetric = widget_properties["yMetric"]
   sizeMetric = widget_properties["sizeMetric"]
   xLog = !!widget_properties["xLogarithmic"]
   yLog = !!widget_properties["yLogarithmic"]
   maxItems = widget_properties["maxItems"].to_i

   filter = MeasureFilter.find_by_id(filterId.to_i)
   if filter
     @widget_title = link_to h(filter.name), {:controller => 'measures', :action => 'filter', :id => filter.id, :display => 'list'}
%>

<div class="bubble-chart-widget" id="<%= containerId %>">
  <!--[if lte IE 8 ]> <h3><%= message('widget.unsupported_browser_warning') -%></h3> <![endif]-->

  <!--[if (gte IE 9)|!(IE)]><!-->
  <% if chartTitle %>
  <h3><%= h(chartTitle) -%></h3>
  <% end %>
  <!--<![endif]-->
</div>

<!--[if (gte IE 9)|!(IE)]><!-->
<script>
  (function () {
    var metrics = [
          '<%= xMetric.name -%>', '<%= yMetric.name -%>', '<%= sizeMetric.name -%>'
        ],
        query = [
          'filter=<%= filterId -%>',
          'metrics=' + metrics.join(','),
          'fields=name,longName,qualifier',
          <% if (maxItems > 0) %>
          'pageSize=<%= maxItems -%>',
          <% end %>
          'page=1',
          'sort=metric:' + metrics[0]
        ].join('&'),
        widget = new SonarWidgets.Widget();

    widget
      .type('BubbleChart')
      .source(baseUrl + '/measures/search_filter?' + query)
      .metricsPriority(metrics)
      .height(<%= chartHeight -%>)
      .options({
        baseUrl: baseUrl + '/dashboard/index/',
        xLog: <%= xLog -%>,
        yLog: <%= yLog -%>,
        noData: '<%= message('no_data') -%>',
        noMainMetric: '<%= message('widget.measure_filter.no_main_metric') -%>'
      })
      .render('#<%= containerId -%>');

    autoResize(500, function() {
      widget.update('#<%= containerId -%>');
    });
  })();
</script>
<!--<![endif]-->
<% else %>
  <p><%= image_tag 'warning.png' %> <%= message 'measure_filter.widget.unknown_filter_warning' -%></p>
<% end %>
